//package cn.com.gc.core.rocketmq.starter;
//
//import GlobalIdGenerator;
//import JsonUtils;
//import cn.com.gc.core.mq.rocketmq.RocketMQListener;
//import cn.com.gc.core.mq.rocketmq.RocketMQMessage;
//import cn.com.gc.core.mq.rocketmq.RocketMqTopic;
//import cn.com.gc.core.redis.RedisClusterServer;
//import cn.com.gc.core.redis.RedisKeys;
//import cn.com.gc.core.rocketmq.starter.core.RocketMQTemplate;
//import cn.com.gc.frame.enums.SysMsgEnumType;
//import cn.com.gc.frame.exception.SystemRuntimeException;
//import org.apache.rocketmq.client.producer.DefaultMQProducer;
//import org.apache.rocketmq.common.message.Message;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
//import org.springframework.stereotype.Service;
//
//
//@Service
//@ConditionalOnClass({DefaultMQProducer.class,RocketMQTemplate.class,RocketMQAutoConfiguration.class})
//@ConditionalOnMissingBean({DefaultMQProducer.class,RocketMQTemplate.class})
//public class RocketMQProducer<T> {
//
//
//
//    @Autowired
//    @Qualifier("rocketMQTemplateService")
//    private RocketMQTemplate rocketMQTemplate;
//
//    @Autowired
//    private RedisClusterServer redisClusterServer;
//
//
//    /**
//     * @Title: 处理消息的接口
//     * @Description:
//     * @param
//     * @return
//     * @throw
//     * @author suven.wang
//     * @date 2018/5/22 17:18
//     *  --------------------------------------------------------
//     *  modifyer    modifyTime                 comment
//     *
//     *  --------------------------------------------------------
//     */
//    public void sendMessage(String topicName,T msg){
//
//        RocketMqTopic topic = RocketMqTopic.getTopName(topicName);
//        if(topic == null){
//            throw new SystemRuntimeException(SysMsgEnumType.MQ_ROCKET_TOPIC_NOT_FOUND);
//        }
//        long globalId = GlobalIdGenerator.get(topic.getModule()).nextId();
//        Message message = new Message();
//        message.setTopic(topic.getTopicName());
//        message.setTags(topic.getTag());
//        message.setDelayTimeLevel(0);
//        message.setKeys(topicName+globalId);
//        //拼装消息队列
//        RocketMQMessage<T> rocketMQMessage = new RocketMQMessage<T>();
//        rocketMQMessage.setGlobalId(globalId);
//        rocketMQMessage.setRetryCount(topic.getFailedRetryCount());
//        rocketMQMessage.setBody(msg);
//        //pb序列化对象
//        message.setBody(JsonUtils.toJsonString(rocketMQMessage).getBytes());
//        redisClusterServer.setex(RedisKeys.MQ_CONSUMER+rocketMQMessage.getGlobalId(), String.valueOf(topic.getFailedRetryCount()),RocketMQListener.CACHE_TIME);
//
//        rocketMQTemplate.convertAndSend(topicName,message);
//    }
//}